package Test06;

//序列化流

import java.io.*;

/*
需求:利用序列化流/对象操作输出流，把一个对象写到本地文件中
 */
public class Test29 {
    public static void main(String[] args) throws IOException {

        //1、创建对象
        Student29 stu = new Student29("zhangsan", 23,"北京");

        //2、创建序列化流对象/对象操作输出流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\工作\\src\\b.txt"));

        //3、写出数据
        oos.writeObject(stu);

        //4、释放资源
        oos.close();
    }
}

class Student29 implements Serializable {

    @Serial
    private static final long serialVersionUID = 2206591602160655745L;

    private String name;
    private int age;
    //transient：瞬态关键字
    //作用：不会把当前属性序列化到本地文件当中
    private transient String address;

    public Student29() {
    }

    public Student29(String name, int age, String address) {
        this.name = name;
        this.age = age;
        this.address = address;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     *
     * @return address
     */
    public String getAddress() {
        return address;
    }

    /**
     * 设置
     *
     * @param address
     */
    public void setAddress(String address) {
        this.address = address;
    }

    public String toString() {
        return "Student29{ name = " + name + ", age = " + age + ", address = " + address + "}";
    }
}